package android.tong;

import android.app.Activity;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class LayOut extends Activity {
	
	private final int WC = LinearLayout.LayoutParams.WRAP_CONTENT;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
//		setContentView(R.layout.layout);
		LinearLayout layout = new LinearLayout(this);
		layout.setOrientation(LinearLayout.VERTICAL);
		
		
		ImageButton btn = new ImageButton(this);
		Drawable dw = this.getResources().getDrawable(R.drawable.tt);
		btn.setImageDrawable(dw);
		btn.setId(R.id.btnOK + 100);
		btn.setOnClickListener(CustClick);
		
		LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(WC, WC);
		layout.addView(btn, param);
		
		ImageButton btn2 = new ImageButton(this);
		dw = this.getResources().getDrawable(R.drawable.tf);
		btn2.setImageDrawable(dw);
		btn2.setId(R.id.btnOK + 101);
		btn2.setOnClickListener(CustClick);
		layout.addView(btn2);
		
		LinearLayout out_layout = new LinearLayout(this);
		out_layout.setOrientation(LinearLayout.HORIZONTAL);
		
		Button btn3 = new Button(this);
		btn3.setText("Cancel");
		btn3.setTextColor(Color.WHITE);
		btn3.setBackgroundColor(Color.RED);
		btn3.setId(R.id.btnOK + 102);
		btn3.setOnClickListener(CustClick);
		out_layout.addView(layout, param);
		
		LinearLayout.LayoutParams param2 = new LayoutParams(WC, WC);
		param2.topMargin = 30;
//		out_layout.addView(layout, param2);
		out_layout.addView(btn3, param2);
		setContentView(out_layout);
		
	}
	
	OnClickListener CustClick = new OnClickListener() {
		
		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			switch (arg0.getId()) {
			case R.id.btnOK + 100:
				setTitle("this is OK button");
				break;
			case R.id.btnOK + 101:
				finish();
				break;
			case R.id.btnOK + 102:
				setTitle("this is Cancel button");
				break;
			default:
				break;
			}
		}
	};
	
}
